package com.example.freshmenclient;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.android.volley.Response;
import com.example.freshmenclient.bean.AnouncenmentDetailsBean;
import com.example.freshmenclient.util.GainDataUtil;
import com.example.freshmenclient.util.UrlUtil;
import com.google.gson.Gson;


import org.json.JSONException;
import org.json.JSONObject;

public class AnouncenMentDetailsActivity extends AppCompatActivity {

    private static final String TAG = "AnouncenMentDetails";

    private TextView tvAnouncenmentTitle;
    private TextView tvAnouncenmentDesc;
    private TextView tvAnouncenmentDate;
    private AnouncenmentDetailsBean anouncenmentDetailsBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anouncen_ment_details);
        initView();
        initData();
    }

    private void initData() {
        String url = UrlUtil.basePath + "freshmenserver/announcement/findone";
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("id", UrlUtil.anouncenmentId);

            GainDataUtil.gainDataForPost(this, url, jsonObject
                    , new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject jsonObject) {
                            Log.e(TAG, "onResponse: " + jsonObject);
                            Gson gson = new Gson();
                            anouncenmentDetailsBean = gson.fromJson(jsonObject.toString(), AnouncenmentDetailsBean.class);
                            tvAnouncenmentTitle.setText(anouncenmentDetailsBean.getData().getTitle());
                            tvAnouncenmentDesc.setText(anouncenmentDetailsBean.getData().getDescription());
                            tvAnouncenmentDate.setText(anouncenmentDetailsBean.getData().getDate());
                        }
                    }, null);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void initView() {
        tvAnouncenmentTitle = findViewById(R.id.tv_anouncenment_title);
        tvAnouncenmentDesc = findViewById(R.id.tv_anouncenment_desc);
        tvAnouncenmentDate = findViewById(R.id.tv_anouncenment_date);
    }

    public void back(View view) {
        finish();
    }
}
